package com.mtu.parser;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;

public class ParserUtil {
	
	public String getHTMLPageSource(String URL, String rollNo) {
		
		String response = null;
		HttpClient client = new HttpClient();
		client.getParams().setParameter("http.useragent", "Test Client");

		PostMethod method = new PostMethod(URL);
		method.addParameter("user_id", rollNo);
		method.addParameter("submit", "Submit");
		method.addParameter("submitted", "TRUE");

		try {
			int returnCode = client.executeMethod(method);
			if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
				System.err.println("The Post method is not implemented by this URI");
			} 
			else {
				response = method.getResponseBodyAsString();
			}
		} 
		catch (Exception e) {
			System.err.println(e);
		} 
		finally {
			method.releaseConnection();
		}
		return response;
	}
	

	public static void main(String args[]) {

		String URL = "http://result.mtu.ac.in/btech_201011.php";
		String rollNo = "1006410001";
		
		ParserUtil ob = new ParserUtil();
		String response = ob.getHTMLPageSource(URL, rollNo);
		
		System.out.println(response);
	}

} 